package com.pk.android.view;

import java.util.ArrayList;
import java.util.List;

import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;

import com.pk.android.R;
import com.pk.android.dummy.temp_source;
import com.pk.android.model.BaseFragment;
import com.pk.android.model.League;

public class MainActivity extends GeneralDrawerActivity 
implements MyLeaguesFragment.OnAllLeaguesClickListener, 
DashboardPK_Fragment.OnMyLeagueClickListener
{

	private String title = "DASHBOARD";
    private List<BaseFragment> fragments;
    
	@Override
	public void onCreate(Bundle savedInstanceState) {		
		super.onCreate(savedInstanceState);
		
		fragments = getFragments();
		SetupPageViewer(fragments, title);

	}
    
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return super.onCreateOptionsMenu(menu);
	}

	@Override
	public void onAllLeaguesClick(int position) {
		
		Intent myIntent = new Intent(MainActivity.this, MyLeaguesActivity.class);
		//myIntent.putExtra("key", value); //Optional parameters
		this.startActivity(myIntent);
		
		//Fragment fragment = new AllLeaguesFragment();
		//getSupportFragmentManager().beginTransaction().setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN).replace(R.id.main_fragment_container, fragment).commit();
	}


	@Override
	public void onMyLeaguesClick(int position) {
		//at position 0 we have the dashboard
		SetPagerCurrentItem(position+1);
	}

	private List<BaseFragment> getFragments(){
		  List<BaseFragment> fList = new ArrayList<BaseFragment>();
		  fList.add(DashboardPK_Fragment.newInstance("My League List"));
		  for(League item : temp_source.getMyLeagueList())
			  fList.add(MyLeaguesFragment.newInstance(item.getName()));
		  return fList;
	}
}
